<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 script 标签引入的方式导出 Excel</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
  const data = [
    ['姓名', '年龄', '性别'],
    ['张三', 20, '男'],
    ['李四', 21, '女'],
  ];

  const worksheet = XLSX.utils.json_to_sheet(data);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'sheet1');

  const excelBuffer = XLSX.write(workbook, {
    type: 'array',
    bookType: 'xlsx',
  });

  const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
  const url = window.URL.createObjectURL(blob);

  const a = document.createElement('a');
  a.href = url;
  a.download = 'my-file.xlsx';
  a.click();
</script>
</body>
</html>
